﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Supermarket.Dal;

namespace Supermarket.Bll
{
    public static class ShoppingCartManager
    {
        public static string CardId { get; set; }

        public static void AddItemForSale(string cartId, int productId, double quantity)
        {
            ShoppingCartDB.AddItemForSale(Guid.Parse(cartId), productId, quantity);
        }

        public static List<object> GetCheckedProduct()
        {
            List<object> products = ShoppingCartDB.GetCheckedProduct(Guid.Parse(CardId));
            return products;            
        }

        public static string CheckOutSale(string CartId)
        {
            Guid cartId = Guid.Parse(CartId);

            try
            {
                ShoppingCartDB.CheckOutSale(cartId);                
                return "Покупката беше изпълнена успешно.";                
            }
            catch (ArgumentOutOfRangeException ex)
            {
                return ex.ParamName;
            }

            catch (Exception ex)
            {
                return "Възникна грешка при обработката на данните! - " + ex.Message;
            }
        }

        //Logic for CheckOutSupply

        public static void AddItemForSupply(string cartId, int productId, decimal productPrice, double quantity)
        {
            ShoppingCartDB.AddItemForSupply(Guid.Parse(cartId), productId, productPrice, quantity);
        }

        public static List<object> GetCheckedProductForSupply()
        {
            List<object> products = ShoppingCartDB.GetCheckedProductForSupply(Guid.Parse(CardId));
            return products;
        }

        public static string CheckOutSupply(string CartId)
        {
            Guid cartId = Guid.Parse(CardId);

            try
            {
                ShoppingCartDB.CheckOutSupply(cartId);
                return "Зареждането беше изпълнено успешно.";  
            }
            catch (ArgumentOutOfRangeException ex)
            {
                return ex.ParamName;
            }
            catch (Exception ex)
            {
                return "Възникна грешка при обработката на данните! - " + ex.Message;
            }
        }
    }
}
